package com.atstudy.headline.web.admin.controller.media;

import com.atstudy.headline.entity.MediaResources;
import com.atstudy.headline.result.Result;
import com.atstudy.headline.web.admin.service.MediaResourcesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/media")
public class MediaController {

    @Qualifier("mediaResourcesServiceImpl")
    @Autowired
    private MediaResourcesService mediaService;

    // 获取媒体资源列表
    @GetMapping
    public Result<List<MediaResources>> list() {
        List<MediaResources> media = mediaService.list();
        return Result.ok(media);
    }

    // 删除媒体资源
    @DeleteMapping("/{id}")
    public Result<Void> delete(@PathVariable Integer id) {
        mediaService.removeById(id);
        return Result.ok();
    }

    // 更新媒体资源信息
    @PutMapping("/{id}")
    public Result<Void> update(@PathVariable Integer id, @RequestBody MediaResources media) {
        media.setResourceId(id);
        mediaService.updateById(media);
        return Result.ok();
    }
}